package logic

import (
	"context"
	"fmt"
	"hui-hui/models"

	"hui-hui/hui_hui_rpc/hui_hui_rpc"
	"hui-hui/hui_hui_rpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PushResaLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPushResaLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PushResaLogic {
	return &PushResaLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PushResaLogic) PushResa(in *hui_hui_rpc.PushResaRequest) (*hui_hui_rpc.PushResaResponse, error) {
	// todo: add your logic here and delete this line
	resa := models.Resa{
		UserId:  int(in.UserId),
		PlanId:  int(in.PlanId),
		Comment: in.Comment,
	}
	if models.DB.Create(&resa).Error != nil {
		return nil, fmt.Errorf("服务器繁忙")
	}
	return &hui_hui_rpc.PushResaResponse{}, nil
}
